package com.autumn.annotations.bean.config.imports;

import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * ClassName: MyImportBeanDefinitionRegister
 *
 * @Description:
 * @Author: wangqiuyang
 * @Date: 2022/1/25 1:53 下午
 * History:
 * <author>          <time>          <version>          <desc>
 * wangqiuyang    2022/1/25 1:53 下午   @Version 1.0        描述
 */
public class MyImportBeanDefinitionRegister implements ImportBeanDefinitionRegistrar {

    /**
    * Description: 方法描述
    * @param importingClassMetadata 当前类的注解信息
    * @param registry beanDefinition注册类
    * @return: void
    * @author: wangqiuyang
    * @Date: 2022/1/25 1:53 下午
    */
    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {


        boolean haveRed = registry.containsBeanDefinition("com.autumn.annotations.bean.config.imports.Red");
        boolean haveBlue = registry.containsBeanDefinition("com.autumn.annotations.bean.config.imports.Blue");

        if (haveRed && haveBlue) {
            RootBeanDefinition def = new RootBeanDefinition(Rainbow.class);
            registry.registerBeanDefinition("我自己注册的rainbow" , def);
        }

    }
}
